#include "StdAfx.h"
#include "VisionWrapper.h"

CVisionWrapper::CVisionWrapper(CString filename)
{
	m_DLLhInstance = NULL ;				// no DLL loaded
	m_FileName = _T("") ;					// no filename

	FilyVisionType = NULL ;		// no functions setup
	FilyVisionCaption = NULL ;		// no functions setup
	FilyVisionConfig = NULL ;		// no functions setup
	//m_pConfig = new CMap<CString, LPCTSTR, ConfigStruct*, ConfigStruct*>();
	if (filename != _T(""))
		LoadDLL(filename) ;
}

CVisionWrapper::~CVisionWrapper()
{
	// release any loaded DLL
	if (m_DLLhInstance != NULL)
		FreeLibrary(m_DLLhInstance) ;		// release library
}


bool CVisionWrapper::LoadDLL(CString filename)
{
	m_FileName = filename ;
	m_DLLhInstance = AfxLoadLibrary(filename) ;

	if (m_DLLhInstance != NULL)
	{
		// get pointers to functions
		// add others here
		FilyVisionType = (VisionType)GetProcAddress(m_DLLhInstance, "VisionType") ;
		FilyVisionCaption = (VisionCaption)GetProcAddress(m_DLLhInstance, "VisionCaption") ;
		FilyVisionConfig = (VisionConfig)GetProcAddress(m_DLLhInstance, "VisionConfig") ;
		if( FilyVisionConfig != NULL)
		{
			FilyVisionConfig(&m_pConfig);
		}
	}
	return (m_DLLhInstance != NULL) ;
}

bool CVisionWrapper::FreeDLL()
{
	// release any loaded DLL
	if (m_DLLhInstance != NULL)
	{
		FreeLibrary(m_DLLhInstance) ;		// release library
		m_DLLhInstance = NULL ;
		m_FileName = _T("") ;
		// kill any function pointers
		FilyVisionType = NULL ;
		FilyVisionCaption = NULL ;
		FilyVisionConfig = NULL ;
	}
	return true ;
}

// GetVisionType
int CVisionWrapper::GetVisionType(void)
{
	if(FilyVisionType != NULL)
	{
		return FilyVisionType();
	}
	return -1;
}


// GetVisionCaption
CString CVisionWrapper::GetVisionCaption(void)
{
	if(FilyVisionCaption != NULL)
	{
		return FilyVisionCaption();
	}
	return _T("");
}
